package com.zhangxu.junior.controller;

import com.github.pagehelper.PageHelper;
import com.zhangxu.junior.domain.PageParam;
import com.zhangxu.junior.domain.Student;
import com.zhangxu.junior.service.impl.StudentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author zhang xu
 * @Date 2022/6/20 16:05
 * @PackageName:com.zhangxu.junior.controller
 * @ClassName: StudentController
 * @Description: TODO
 * @Version 1.0
 */
@RestController
public class StudentController {

    @Autowired
    StudentServiceImpl studentService;


    /**
     *
     * @param student
     * @param pageNum
     * @param pageSize
     * @return
     * description: 此方法用于获取学生列表
     *    1、当Student为空时获取所有学生
     *    2、当Student的studName有值时进行模糊查询
     *    3、当Student的sex属性有值时进行性别精确查询
     */

    @GetMapping("/studentList")
    public List<Student> list(@RequestBody Student student,Integer pageNum,Integer pageSize){

        PageParam pageParam =new PageParam();

        pageParam.setPageNum(pageNum);
        pageParam.setPageSize(pageSize);
        PageHelper.startPage(pageParam);

        return studentService.selectStudentList(student);
    }



    /**
     *
     * @param ids
     * @return
     * 删除学生信息、可实现批量删除
     */
    @DeleteMapping("/deletStudents")
    public boolean deleteStudentByIds(@RequestBody Long[] ids){
        return studentService.deleteStudentByIds(ids);
    }

    /**
     * 新增学生信息
     * @param student
     * @return
     */
    @PostMapping("/insertStudent")
    public boolean insertStudent(@RequestBody Student student){
        return studentService.insertStudent(student);
    }

    /**
     * 修改学生信息
     * @param student
     * @return
     */
    @PostMapping("/updateStudent")
    public boolean updateStudent(@RequestBody Student student){
        return studentService.updateStudent(student);
    }

    @GetMapping("/studentDetail")
    public Student selectStudentDetail(@RequestBody Student student){
        return studentService.selectStudentDetail(student);
    }

}
